(define-module (staging runcache)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix git-download)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages gawk)
  #:use-module (guix build-system trivial))

(define-public runcache
  (package
    (name "runcache")
    (version "0.1")
    (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/moul/runcache.git")
                    (commit "4bd818facaabc964f812e324281175e11b427c85")))
              (file-name (git-file-name name version))
              (sha256
               (base32
                "0pch8znlhf4zah9xfx07r0kqr78rx7gvcfn05vk8sy1cq7ami0jx"))))
    (build-system trivial-build-system)
    (arguments
     `(#:modules ((guix build utils))
       #:builder (begin
                   (use-modules (guix build utils))
                   (let* ((runcache-script (string-append (assoc-ref %build-inputs "source")
                                                          "/runcache"))
                          (bin-dir (string-append %output "/bin/"))
                          (target-script (string-append bin-dir "/runcache"))
                          (awk (string-append (assoc-ref %build-inputs "gawk")
                                              "/bin/awk"))
                          (which (string-append (assoc-ref %build-inputs "which")
                                                "/bin/which"))
                          (md5sum (string-append (assoc-ref %build-inputs "coreutils")
                                                 "/bin/md5sum"))
                          (bash (string-append (assoc-ref %build-inputs "bash")
                                               "/bin/bash")))
                     (mkdir-p bin-dir)
                     (copy-file runcache-script target-script)
                     (chmod target-script #o755)
                     (substitute* target-script
                       (("/bin/bash") bash)
                       (("awk") awk)
                       (("which") which)
                       (("md5sum") md5sum))
                     #t))))
    (inputs
     `(("bash" ,bash)
       ("coreutils" ,coreutils)
       ("gawk" ,gawk)
       ("which" ,which)))
    (home-page "https://github.com/moul/runcache")
    (synopsis "Shell command caching")
    (description "runcache provides ccache-style caching for unix commands.")
    (license license:expat)))
